package com.primaryedu.ui.app.growstep;

import com.primaryedu.R;
import com.primaryedu.bean.GradelistBean;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class GradeListAdapter extends BaseAdapter {

    private List<GradelistBean.DataBean.ListBean> list = new ArrayList<>();
    private LayoutInflater inflater;
    @SuppressWarnings("unused")
    private Context context;
    private GradeListAdapter.ViewHolder viewHolder;

    public GradeListAdapter(Activity context, List<GradelistBean.DataBean.ListBean> list) {
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public void updateGradeView(List<GradelistBean.DataBean.ListBean> nowList) {
        this.list = nowList;
        this.notifyDataSetChanged();//强制动态刷新数据进而调用getView方法
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder = null;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_grade_list, null);
            viewHolder.tv_class_grade = (TextView) convertView.findViewById(R.id.tv_class_grade);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (GradeListAdapter.ViewHolder) convertView.getTag();
        }
        GradelistBean.DataBean.ListBean gb = list.get(position);
        viewHolder.tv_class_grade.setText(gb.getClassName());

        return convertView;
    }

    class ViewHolder {
        TextView tv_class_grade;
    }
}
